﻿namespace Maple.Weixin.MP.Entities.Messages
{
    public class ResponseMusic : ResponseMedia, IResponseService
    {
        private string thumbMediaId;

        internal ResponseMusic() { }

        public ResponseMusic(string thumbMediaId) {
            this.thumbMediaId = thumbMediaId;
        }

        public static ResponseMusic CreateByFile(string fileName, out string result)
        {
            var responseMusic = new ResponseMusic();
            var thumbMediaId = responseMusic.UploadMedia(fileName, out result);
            if (string.IsNullOrEmpty(thumbMediaId))
                return null;
            responseMusic.thumbMediaId = thumbMediaId;
            return responseMusic;
        }

        public ResponseMusic(string thumbMediaId, string title, string description, string musicUrl, string hqMusicUrl)
            : this(thumbMediaId) {
            this.Title = title;
            this.Description = description;
            this.MusicUrl = musicUrl;
            this.HQMusicUrl = hqMusicUrl;
        }

        public string Title { get; set; }
        public string Description { get; set; }
        public string MusicUrl { get; set; }
        public string HQMusicUrl { get; set; }

        #region Implementation of IResponseService

        public ResponseMessageBase Handle(RequestMessageBase requestMessage) {
            var responseMessage = requestMessage.CreateMusicResponse(thumbMediaId);
            responseMessage.Title = Title;
            responseMessage.Description = Description;
            responseMessage.MusicUrl = MusicUrl;
            responseMessage.HQMusicUrl = HQMusicUrl;
            return responseMessage;
        }

        #endregion

        #region Overrides of ResponseMedia

        protected override UploadMediaType MediaType {
            get { return UploadMediaType.Thumb; }
        }

        #endregion
    }
}
